﻿using System;
using UniRx;
using UnityEngine;
using UnityEngine.UI;

namespace MyNamespace
{
	public class ReactivePropertyExample : MonoBehaviour
	{
		private IReadOnlyReactiveProperty<string> mInputUsername;
		private ReactiveProperty<string> mInputPassword = new ReactiveProperty<string>();

		private void Awake()
		{
			// 获取组件
			var inputUsername = transform.Find("InputUsername").GetComponent<InputField>();
			var inputPassword = transform.Find("InputPassword").GetComponent<InputField>();
			var text = transform.Find("Text").GetComponent<Text>();

			// 注册监听

			mInputUsername = inputUsername.OnValueChangedAsObservable()
				.ToReactiveProperty();
			
			inputPassword.onValueChanged.AddListener((value) =>
			{
				mInputPassword.Value = value;
			});
			
			mInputUsername.SubscribeToText(text);
		}
	}
}